//
//  FundListCell.m
//  LeaveLight
//
//  Created by pro1 on 2019/3/5.
//  Copyright © 2019 xsl. All rights reserved.
//

#import "FundListCell.h"
#import "UIView+XTExtension.h"


@implementation FundListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
//    self.selectionStyle = UITableViewCellSelectionStyleNone;
    [self.TopImage setCorner:5.0];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setContentLabelText:(NSString *)text{
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing = 10.0; // 调整行间距
    NSRange range = NSMakeRange(0, [text length]);
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:range];
    self.contentLab.attributedText = attributedString;
}

- (void)updateUIWithModel:(TemplateModel *)dataModel
{
    self.model = dataModel;
    [self.TopImage sd_setImageWithURL:[NSURL URLWithString:self.model.chicken_model.images] placeholderImage:[UIImage imageNamed:@"图片空白加载页"]];
    [self setContentLabelText:self.model.chicken_model.content];
    [self.collec setSelected:(self.model.chicken_model.is_collect == 1 ? NO : YES)];
}

- (IBAction)collectClick:(QMUIButton *)sender {
    
    if (sender.selected) {
        
        [self deleteCollectWithid:StringIsEmpty(self.model.chicken_model.chicken_id) ? self.model.chicken_model.ID : self.model.chicken_model.chicken_id Success:^{
            sender.selected = NO;
            self.model.chicken_model.is_collect = 1;
        } failed:^(NSString * _Nonnull error) {
            [QMUITips showWithText:error];
        }];
    }else
    {
        weakify(self);
        [self addCollectWithid:StringIsEmpty(self.model.chicken_model.chicken_id) ? self.model.chicken_model.ID : self.model.chicken_model.chicken_id imgUrl:self.model.chicken_model.images template_type:self.model.chicken_model.template_type Success:^{
            strongify(self);
            sender.selected = YES;
            self.model.chicken_model.is_collect = 2;
        } failed:^(NSString * _Nonnull error) {
            [QMUITips showWithText:error];
        }];
    }
}

- (IBAction)editClick:(QMUIButton *)sender {
    EditController * edit = [[EditController alloc]initWithNibName:@"EditController" bundle:nil];
    self.model.chicken_model.is_edit = YES;
    edit.model = self.model;
    edit.isEdit = YES;
    [[self getViewcontrollerView:sender].navigationController pushViewController:edit animated:YES];
}


- (IBAction)copyClick:(id)sender {
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = self.model.chicken_model.content;
    [QMUITips showSucceed:@"复制文本成功"];
}


@end
